require("module-alias/register"); // 使用路径别名
import * as dotenv from "dotenv"; // 环境变量
import express from "express";
import expressWs from "express-ws";
import bodyParser from "body-parser";
import { requestLogger, logger } from "@/utils/log";
import { globalData } from "@/store";
import { getIpAddress } from "@/utils/utils";
import path from "path";
import router from "@/router";
import { wechaty } from "@/controllers/webSocket/";

// 使用环境变量
dotenv.config();

const { app, getWss, applyTo } = expressWs(express());

// 接收 post 请求
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// 静态资源
app.use(express.static(path.join(__dirname, "public")));

logger.info(0, "服务器重启");
app.use(router);

globalData.getWss = getWss;
app.ws("/wechaty", wechaty);

app.get("/", (req, res) => {
  res.send("服务器已启动");
});

const port = process.env.PORT || 3201;

app.listen(port, () => {
  console.log(`服务器已启动：http://127.0.0.1:${port}`);
});

